﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DCSLibrary;
using Utils.DC.Web.UI;
using Utils.DCSControl;
using Utils.Entity;

public partial class Admin_Module_thay_doi_mat_khau : System.Web.UI.UserControl
{
    #region Cac bien dung chung
    UsersUI objUser = new UsersUI();
    MessageBox messageBox = new MessageBox();
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UserEntity users = ((dcPage)this.Page).CurrentUser;

            if (users != null)
            {
                txtUserID.Value = users.UserID.ToString();
            }
        }
    }

    protected void btnCreate_Click(object sender, EventArgs e)
    {
        if (txtUserID.Value.Trim() != "")
        {
            try
            {
                int result = objUser.ChangePassword(Convert.ToInt32(txtUserID.Value), Security.Encrypt(txtOldPassword.Text), Security.Encrypt(txtNewPassword.Text) );
                if (result == 1)
                {
                    Response.Write(messageBox.Alert(MessageBox.MESSAGE_UPDATE_SUCCESSFULLY));
                }
                else
                {
                    Response.Write(messageBox.Alert(MessageBox.MESSAGE_INCORRECT_PASSWORD));
                }
            }
            catch (Exception ex)
            {
                Response.Write(messageBox.Alert(MessageBox.MESSAGE_CONFILCT_DATA));
            }
        }
    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        ReInsertData();
    }


    private void ReInsertData()
    {
        txtNewPassword.Text = "";
        txtOldPassword.Text = "";
        txtReNewPassword.Text = "";
    }
}
